From: Jesús Martínez Novo Date: Sat, 17 Jun 2017 11:56:14 +0000 (+0200) Subject: Performance: Shortcut Language::truncate if there's no need to truncate X-Git-Tag: 1.31.0-rc.0~917 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=92e74356e2afec139d2dcafa55f9de5609f32ebc;p=lhc%2Fweb%2Fwiklou.git Performance: Shortcut Language::truncate if there's no need to truncate Return the unmodified string if there's no need to truncate it without doing a not-so-trivial round of getting a message from the message cache. Change-Id: I11ac88672aeb9d1c4f5709b79ad2d17223bd64d8 --- diff --git a/languages/Language.php b/languages/Language.php index fdf2d05d9d..27c9faf307 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3489,15 +3489,16 @@ class Language { * @return string */ function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) { + # Check if there is no need to truncate + if ( strlen( $string ) <= abs( $length ) ) { + return $string; // no need to truncate + } # Use the localized ellipsis character if ( $ellipsis == '...' ) { $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped(); } - # Check if there is no need to truncate if ( $length == 0 ) { return $ellipsis; // convention - } elseif ( strlen( $string ) <= abs( $length ) ) { - return $string; // no need to truncate } $stringOriginal = $string; # If ellipsis length is >= $length then we can't apply $adjustLength